package net.lab1024.smartadmin.module.business.driveshaft.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.business.driveshaft.dao.DriveshaftDao;
import net.lab1024.smartadmin.module.business.driveshaft.domain.dto.DriveshaftAddDTO;
import net.lab1024.smartadmin.module.business.driveshaft.domain.dto.DriveshaftQueryDTO;
import net.lab1024.smartadmin.module.business.driveshaft.domain.dto.DriveshaftUpdateDTO;
import net.lab1024.smartadmin.module.business.driveshaft.domain.entity.DriveshaftEntity;
import net.lab1024.smartadmin.module.business.driveshaft.domain.vo.DriveshaftExcelVO;
import net.lab1024.smartadmin.module.business.driveshaft.domain.vo.DriveshaftVO;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import net.lab1024.smartadmin.util.SmartPageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [ ������ ]
 *
 * @author �Ζ�
 * @version 1.0
 * @company ��������
 * @copyright (c)  ��������Inc. All rights reserved.
 * @date 2021-11-19 11:18:27
 * @since JDK1.8
 */
@Service
public class DriveshaftService {

    @Autowired
    private DriveshaftDao driveshaftDao;

    /**
     * ���ݱ�Ų�ѯ
     */
    public Boolean select(String sn,Long id){
        QueryWrapper<DriveshaftEntity> queryWrapper= new QueryWrapper<>();
        queryWrapper.lambda().like(DriveshaftEntity::getSn,sn);
        if(id!=null){
            queryWrapper.lambda().ne(DriveshaftEntity::getId, id);
        }
        return  driveshaftDao.selectList(queryWrapper).size()>0;
    }

    /**
     * ����id��ѯ
     */
    public DriveshaftEntity getById(Long id){
        return  driveshaftDao.selectById(id);
    }

    /**
     * ��ҳ��ѯ
     * @author �Ζ�
     * @date 2021-11-19 11:18:27
     */
    public ResponseDTO<PageResultDTO<DriveshaftVO>> queryByPage(DriveshaftQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<DriveshaftVO> voList = driveshaftDao.queryByPage(page, queryDTO);
        PageResultDTO<DriveshaftVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * ���
     * @author �Ζ�
     * @date 2021-11-19 11:18:27
     */
    public ResponseDTO<String> add(DriveshaftAddDTO addDTO) {
        DriveshaftEntity entity = SmartBeanUtil.copy(addDTO, DriveshaftEntity.class);
        driveshaftDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * �༭
     * @author �Ζ�
     * @date 2021-11-19 11:18:27
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(DriveshaftUpdateDTO updateDTO) {
        DriveshaftEntity entity = SmartBeanUtil.copy(updateDTO, DriveshaftEntity.class);
        driveshaftDao.updateById(entity);
        return ResponseDTO.succ();
    }

    /**
     * ɾ��
     * @author �Ζ�
     * @date 2021-11-19 11:18:27
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        driveshaftDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * ��ѯȫ����������
     * @author �Ζ�
     * @date 2021-11-19 11:18:27
     */
    public List<DriveshaftExcelVO> queryAllExportData(DriveshaftQueryDTO queryDTO) {
        return driveshaftDao.queryAllExportData( queryDTO);
    }

    /**
     * ������ѯ��������
     * @author �Ζ�
     * @date 2021-11-19 11:18:27
     */
    public List<DriveshaftExcelVO> queryBatchExportData(List<Long> idList) {
        return driveshaftDao.queryBatchExportData(idList);
    }
}
